#!/usr/bin/make -f

NAME=distro-tracker

%:
	dh $@ --with python2,sphinxdoc,systemd --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C docs html

override_dh_auto_install:
	dh_auto_install
	install -m 755 -D manage.py debian/$(NAME)/usr/bin/distro-tracker
	# Move settings in /etc/
	for dir in `find debian/tmp/ -type d -wholename '*/distro_tracker/project/settings'`; do \
	    if [ ! -e debian/tmp/etc/$(NAME)/settings ]; then \
		mkdir -p debian/tmp/etc/$(NAME)/; \
		mv $$dir debian/tmp/etc/$(NAME)/; \
	    else \
		rm -rf $$dir; \
	    fi; \
	    ln -sf /etc/$(NAME)/settings $$dir; \
	done
	# Replace selected.py with a symlink to production setttings
	ln -sf production.py debian/tmp/etc/$(NAME)/settings/selected.py
	# Clean up .pyc files
	rm -f debian/tmp/etc/$(NAME)/settings/*.pyc

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	./manage.py test django_email_accounts/ distro_tracker/
endif

override_dh_systemd_enable:
	dh_systemd_enable --name=distro-tracker-mail
